/*
 * Copyright (c) 2020-2099 the original author or authors. All rights reserve.
 */
package org.tianyun.cloud.security.token.strategy;

import org.tianyun.cloud.security.token.common.AccessToken;
import org.tianyun.cloud.security.token.common.Authentication;

import java.security.Principal;

/**
 * token策略，用于创建、解析token
 *
 * @auther ebert_chan
 */
public interface TokenStrategy {

    /**
     * 生成AccessToken
     *
     * @param authentication
     * @return
     * @auther ebert_chan
     */
    AccessToken createAccessToken(Authentication authentication);

    /**
     * 更新rawValue
     *
     * @param authentication
     * @auther ebert_chan
     */
    void restoreRawValue(Authentication authentication);

    /**
     * 获取AccessToken
     *
     * @param principal
     * @return
     * @auther ebert_chan
     */
    AccessToken getAccessToken(Principal principal);

    /**
     * 移除AccessToken
     *
     * @param principal
     * @auther ebert_chan
     */
    void removeAccessToken(Principal principal);

    /**
     * 解析access token value，如果token为有效的返回AccessToken，无效token返回null
     *
     * @param value
     * @return
     * @auther ebert_chan
     */
    AccessToken readAccessToken(String value);

}
